const fetchYoutubeSubtitle = async (vid) => {
  const { events } = await fetch(
    `https://www.youtube.com/api/timedtext?v=${vid}&ei=rGxIZ5ClNLqx1d8PyLvP-A4&caps=asr&opi=112496729&exp=xbt&xoaf=5&hl=zh-CN&ip=0.0.0.0&ipbits=0&expire=1732824860&sparams=ip%2Cipbits%2Cexpire%2Cv%2Cei%2Ccaps%2Copi%2Cexp%2Cxoaf&signature=B91CB2D1A1835EF1E1C8C6C39BB6374D8B800835.47203AB9A535C8E6AA6260F0DF592C81F4AF9C6E&key=yt8&kind=asr&lang=en&fmt=json3&xorb=2&xobt=3&xovt=3&cbr=Chrome&cbrver=131.0.0.0&c=WEB&cver=2.20241126.01.00&cplayer=UNIPLAYER&cos=Windows&cosver=10.0&cplatform=DESKTOP`,
    {
      headers: {
        accept: "*/*",
        "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-US;q=0.6",
        priority: "u=1, i",
        "sec-ch-ua":
          '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
        "sec-ch-ua-arch": '"x86"',
        "sec-ch-ua-bitness": '"64"',
        "sec-ch-ua-form-factors": '"Desktop"',
        "sec-ch-ua-full-version": '"131.0.6778.86"',
        "sec-ch-ua-full-version-list":
          '"Google Chrome";v="131.0.6778.86", "Chromium";v="131.0.6778.86", "Not_A Brand";v="24.0.0.0"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-model": '""',
        "sec-ch-ua-platform": '"Windows"',
        "sec-ch-ua-platform-version": '"15.0.0"',
        "sec-ch-ua-wow64": "?0",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "x-client-data":
          "CIu2yQEIpLbJAQipncoBCKz3ygEIlKHLAQiFoM0BCOfQzQEIqsnOAQj5yc4BCI/KzgEI0s3OAQjGz84BCPTPzgEIrdDOAQj/0M4BCJzSzgEIjtPOAQiy084BGPXJzQEYu8zOAQ==",
        "x-goog-authuser": "0",
        "x-goog-visitor-id": "CgsybGhndU5vaUxQMCis2aG6BjIKCgJTRxIEGgAgMg%3D%3D",
        "x-youtube-ad-signals":
          "dt=1732799663484&flash=0&frm&u_tz=480&u_his=8&u_h=720&u_w=1280&u_ah=672&u_aw=1280&u_cd=24&bc=31&bih=569&biw=667&brdim=0%2C0%2C0%2C0%2C1280%2C0%2C1280%2C672%2C683%2C585&vis=1&wgl=true&ca_type=image&bid=ANyPxKoH4WPO_G1ZNNahir8jx8diBlkDAhGF2qRCzL58CxUkdRtmH8qySd6N2ULElLrXrjiS_O_PxNGuMDrrAXYOYQss3MAxaQ",
        "x-youtube-client-name": "1",
        "x-youtube-client-version": "2.20241126.01.00",
        "x-youtube-device":
          "cbr=Chrome&cbrver=131.0.0.0&ceng=WebKit&cengver=537.36&cos=Windows&cosver=10.0&cplatform=DESKTOP",
        "x-youtube-identity-token":
          "QUFFLUhqbXR1YmlMWlhCOTZfM1lBajZjZnZ6eXpzeG5tQXw=",
        "x-youtube-page-cl": "700425332",
        "x-youtube-page-label": "youtube.desktop.web_20241126_01_RC00",
        "x-youtube-time-zone": "Asia/Shanghai",
        "x-youtube-utc-offset": "480",
        cookie:
          "LOGIN_INFO=AFmmF2swRQIhAJdjoKNtCnWid3nBe7AYPVn5pls4duZEANpgnFeV7skPAiAMPjhYe4wvhV_1g1ni6YQpyNbkcbuMw5pax8CvxJ7f5Q:QUQ3MjNmenNPRFZZT1gxVURLYm5CUjdobFFncmVuLTYwOGdiRFRpYVA1YUk2elVoRmcyc0E2UXZQeVNobm1BU0tLNGZPbVU5YjBmbE94cjhVclZWY0I4SDZ0SmRja2hxS2FxajhoYUViNHNQSVR6V2FzeE5xRmlKU1FiRVZBZng1dzI5NTVYMmpZcnlDWVE4SjN5djNPTTZEaTlHa3FqYkhn; PREF=f7=4100&tz=Asia.Shanghai&f4=4000000&f5=30000; VISITOR_INFO1_LIVE=2lhguNoiLP0; VISITOR_PRIVACY_METADATA=CgJTRxIEGgAgMg%3D%3D; SID=g.a000qQhTPPyJdRZF5c8W6oeF2BtNY09zBU7hlh8Zis1j_t8TND3NiPuKfNRREH4Dicd_IbIAOwACgYKAWUSARcSFQHGX2MiUf3TPf94DYsTCNsY4-FXtxoVAUF8yKramxoUA93mi0OelVw2G-oS0076; __Secure-1PSID=g.a000qQhTPPyJdRZF5c8W6oeF2BtNY09zBU7hlh8Zis1j_t8TND3NW5-1G4j-yGDSEtnS2-fVngACgYKASUSARcSFQHGX2MixUy7h2iRi-hawIzT8fLU5xoVAUF8yKrSFKBGTrHSjLmIzVwvrV0O0076; __Secure-3PSID=g.a000qQhTPPyJdRZF5c8W6oeF2BtNY09zBU7hlh8Zis1j_t8TND3NZSyRJzvCQRhWP06rmJqHfQACgYKAVQSARcSFQHGX2MiaOtselbgBHqb_rAx0Fix7RoVAUF8yKp0NB5NjI_WRwHeM1yPZi7X0076; HSID=A--ROWPCCzp2Oeahj; SSID=AuyzFuSdyRWSE4aE3; APISID=RKIFW3H8Y5BirDBZ/A8ZuewXGyyU-AmODu; SAPISID=sbo2EEV3-kFdeoTM/AkZWxYlT1KtOL_aj2; __Secure-1PAPISID=sbo2EEV3-kFdeoTM/AkZWxYlT1KtOL_aj2; __Secure-3PAPISID=sbo2EEV3-kFdeoTM/AkZWxYlT1KtOL_aj2; YSC=ZSryA3fzQHU; __Secure-1PSIDTS=sidts-CjIBQT4rX3Fvez-1TAfWH7zx5KSBlL28Zbie-lM9_PcHFqOw5lzQTBcouo9XNSLZwxHplxAA; __Secure-3PSIDTS=sidts-CjIBQT4rX3Fvez-1TAfWH7zx5KSBlL28Zbie-lM9_PcHFqOw5lzQTBcouo9XNSLZwxHplxAA; SIDCC=AKEyXzXCLag-93PO5YvRPoOlqgiB_uOKbUB2UIY0CI21UeDYQy2yNh5Kf5gZr3GlWIakk7irEKc; __Secure-1PSIDCC=AKEyXzVkyFIz692vAGNtecR2p_hfOA2XzlhYX3qFRV2EeHxoT0bvF1RZ9g6ebB2gztjee0XVGpg; __Secure-3PSIDCC=AKEyXzWEb0v0CLmCr0eAlLegMmC36wF0PRIaKhV8XrFTopt5tLCsqd9WTQg1R3X7j4m22PybDg",
        Referer:
          "https://www.youtube.com/watch?v=1wnIdTRzJcI&ab_channel=MorganStanley",
        "Referrer-Policy": "origin-when-cross-origin",
      },
      body: null,
      method: "GET",
    }
  ).then((res) => res.json());

  console.log(events);
};

fetchYoutubeSubtitle("1wnIdTRzJcI");

exports.processYoutubeSubtitle = (subtitleList) => {
  let content = "";
  if (Array.isArray(subtitleList)) {
    subtitleList.forEach((item) => {
      if (Array.isArray(item.segs)) {
        item.segs.forEach((seg) => {
          content += seg.utf8;
        });
      }
    });
  }
  content;
};
